<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Array</title>
</head>

<body>
    <script>
        // 数组定义的方式
        let fruits = new Array(3)
        fruits[0] = '苹果'
        fruits[1] = '鸭梨'
        fruits[2] = '桃子'

        fruits[999] = '火龙果'
        console.log(fruits, fruits.length)

        fruits.length = 2
        console.log(fruits, fruits.length)

        // 一般不用
        fruits = new Array('苹果', '鸭梨', '桃子')
        console.log(fruits)

        // 数组的初始值确定的话
        fruits = ['苹果', '鸭梨', '桃子', '西瓜', '木瓜']
        console.log(fruits)

        // 动态创建一个数组，1-100之间的整数放入该数组
        let nums = []
        for (let i = 1; i <= 100; i++) {
            nums[i - 1] = i
        }
        console.log(nums) 

        // 动态创建一个数组，1-100之间能被3或者5整除的数
        nums = []
        for (let i = 1; i <= 100; i++) {
            if (i % 3 === 0 || i % 5 === 0) {
                nums.push(i)
            }
        }
        console.log(nums)

        var arr1 = [1, 2, 3]
        var arr2 = [2, 3]
        var result = arr1.concat(arr2)
        console.log(result)
        console.log(result.join('*'))

        var num = result.pop()
        console.log(num, result)

        var arr = [1, 2, 3, 2, 4, 6, 7, 5, 10, 20, 30]
        //			arr.reverse()
        //			console.log(arr)
        //			
        //			var temp = arr.slice(1,1)
        //			console.log(temp,arr)

        arr.sort(function (a, b) { console.log(a, b); return a - b })
        console.log(arr)

        // 删掉数组中的某些项
        arr.splice(1, 3)
        console.log(arr)

        arr.unshift(99, 35)
        console.log(arr)
    </script>
</body>

</html>